package tools

import com.aliyuncs._
import com.aliyuncs.dm.model.v20151123._
import com.aliyuncs.exceptions._
import com.aliyuncs.profile._
/**
  * 阿里邮件发送服务
  * Created by isaac on 16/1/9.
  */
class AliEmail(accessKey:String, accessSecret:String) {
  val client = new DefaultAcsClient(DefaultProfile.getProfile("cn-hangzhou", accessKey, accessSecret))
  def sendMail(address:String,title:String,body:String)={
    try {
      val request = new SingleSendMailRequest()
      request.setAccountName("error@alimail.handuser.com")
      request.setAddressType(1)
      request.setTagName("error")
      request.setReplyToAddress(true)
      request.setToAddress(address)
      request.setSubject(title)
      request.setHtmlBody(body)
      val httpResponse = client.getAcsResponse(request)
      true
    }
    catch {
      case e:Exception=>
        e.printStackTrace()
        false
    }
  }
}
